﻿// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Collections.Generic;
using System.Windows.Forms;

using Emotive.Otf.OtxEditor.Core;
using Emotive.Otf.OtxEditor.Dom;
using Emotive.Otf.OtxEditor.Project;
using Emotive.Otf.OtxEditor.Refactoring;

namespace Emotive.Otf.OtxEditor.Gui.ClassBrowser
{
    /// <summary>
    /// This class reperesents the base class for all nodes in the
    /// class browser.
    /// </summary>
    public class DerivedTypesNode : ExtFolderNode
    {
        IProject project;
        IClass c;

        public override bool Visible
        {
            get
            {
                ClassBrowserFilter filter = ClassBrowserPad.Instance.Filter;
                return (filter & ClassBrowserFilter.ShowBaseAndDerivedTypes) != 0;
            }
        }

        public IProject Project
        {
            get
            {
                return project;
            }
        }

        public DerivedTypesNode(IProject project, IClass c)
        {
            sortOrder = 1;

            this.project = project;
            this.c = c;
            Text = ResourceService.GetString("MainWindow.Windows.ClassBrowser.DerivedTypes");

            OpenedIcon = "ProjectBrowser.Folder.Open";
            ClosedIcon = "ProjectBrowser.Folder.Closed";

            Nodes.Add(new TreeNode(ResourceService.GetString("Emotive.Otf.OtxEditor.Gui.Pads.ClassScout.LoadingNode")));
        }

        protected override void Initialize()
        {
            base.Initialize();
            Nodes.Clear();

            List<IProjectContent> contentList = new List<IProjectContent>();
            //if (ProjectService.OpenSolution != null)
            //{
            //    foreach (IProject project in ProjectService.OpenSolution.Projects)
            //    {
            //        IProjectContent projectContent = ParserService.GetProjectContent(project);
            //        if (projectContent != null)
            //        {
            //            contentList.Add(projectContent);
            //        }
            //    }
            //}
            foreach (IClass derivedClass in RefactoringService.FindDerivedClasses(c, contentList, true))
            {
                new ClassNode(project, derivedClass).AddTo(this);
            }

            if (Nodes.Count == 0)
            {
                SetIcon(ClosedIcon);
                OpenedIcon = ClosedIcon = null;
            }
        }
    }
}
